package com.enjoy.stub;

import com.xiangxue.jack.stub.StubService;

/**
 * @Classname LocalStubProxy
 * Date 2021/6/27 21:00
 * Version 1.0
 *
 * 接管了studService的调用
 *
 * 只有这个类才会决定要不要远程调用
 */
public class LocalStubProxy implements StubService {

    private StubService stubService;

    //这个必须要，传stubService实例本身
    public LocalStubProxy(StubService stubService) {
        this.stubService = stubService;
    }

    @Override
    public String stub(String s) {
        //代码在客户端执行，你可以在客户端做ThreadLocal本地缓存，或者校验参数之类工作的
        try {
            //用目标对象掉对应的方法  远程调用
            return stubService.stub(s);
        }catch (Exception e) {
            //用来降级
            System.out.println("降级数据");
        }
        //掉完后又执行代码
        return null;
    }
}
